
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书信息详情</title>
<script src="../../scripts/boot.js" type="text/javascript"></script>
<script src="../../demo/demo.css" type="text/javascript"></script>
  <style type="text/css">
  html, body
  {        
      padding:0;
      margin:0;
      border:0;
      height:100%;
      overflow:hidden;
  }
    .asLabel .mini-textbox-border,
    .asLabel .mini-textbox-input,
    .asLabel .mini-buttonedit-border,
    .asLabel .mini-buttonedit-input,
    .asLabel .mini-textboxlist-border
    {
        border:0;background:none;cursor:default;
    }
    .asLabel .mini-buttonedit-buttons,
    .asLabel .mini-buttonedit-button,
    .asLabel .mini-textboxlist-close
    {
        display:none;
    }
    .asLabel .mini-textboxlist-item
    {
        padding-right:8px;
    }    
</style>
</head>
<body>
<form id="bookinfoform" method="post">
<input name="id" class="mini-hidden" />
<fieldset style="border:solid 1px #aaa;padding:3px;">
    <legend >图书信息编辑</legend>
    <div style="padding:5px;">
<table>
    <tr>
        <td align="right">图书名称：</td>
        <td >    
            <input name="bookName" class="mini-textbox" emptyText="请输入图书名称"
             required="true" requiredErrorMessage="图书名称不能为空！" />
        </td>

        <td align="right">出版社：</td>
        <td >    
            <input name="publisher" class="mini-textbox" emptyText="请输入图书出版社"
            required="true" requiredErrorMessage="出版社名称不能为空！"/>
        </td>
    </tr>

    <tr>
        <td align="right">作者：</td>
        <td >    
            <input name="author" class="mini-textbox" emptyText="请输入图书作者"
            required="true" requiredErrorMessage="作者名称不能为空！"/>
        </td>

        <td align="right">图书类别：</td>
        <td >    
            <input id="booktype" name="bookType" class="mini-combobox" allowInput="true" 
            showNullItem="true" nullItemText="请选择类别-"  renderer="onBookTypeRenderer"
            url="../../data/booktype.txt" textField="text" valueField="id" 
            required="true" requiredErrorMessage="图书类别不能为空！"/>
        </td>
    </tr>

    <tr>
        <td align="right">剩余数量：</td>
        <td>
            <input name="remain" class="mini-spinner" 
            format="#,0" increment=1 minValue="0" maxValue="200" 
            required="true" requiredErrorMessage="剩余数量不能为空！"/>
        </td>
    </tr>   
</table>            
    </div>
        </fieldset>
        <div style="text-align:center;padding:10px;">   
            <a class="mini-button" onclick="onCancel" style="width:60px;">关闭</a>       
    </div>        
</form>


<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("bookinfoform");
    // 父子组件传值
    function SetData(data) {
        //跨页面传递的数据对象，克隆后才可以安全使用
        data = mini.clone(data);

        $.ajax({
            url:'/bookmanagement/bookinfolistaction?method=queryBookInfoByID&bookId='+data.bookId,
            type:"get",
            dataType: 'json',
            cache: false,
            success: function(res) {
                form.setData(res)
                // 将所有字段设置为已读
                labelModel()
            },
            error: function(xhr, status, error) {
                // 在这里处理错误情况
                console.error('请求失败：' + error);
            }
        })
    }

    // 将字段设置为只读（别忘记加入对应的css）
    function labelModel() {
      var fields = form.getFields()
      console.log('fields',fields)
      for(var i = 0; i < fields.length; i++) {
        var c = fields[i]
        if (c.setReadOnly) {
          c.setReadOnly(true) // 只读
        }
        if (c.setIsValid) {
          c.setIsValid(true) // 去除校验
        }
        if (c.addCls) {
          c.addCls("asLabel") // 增加asLabel外观
        }
      }
    }

    // 确认按钮
    function onOk(e) {
        SaveData();
    }
    // 取消按钮
    function onCancel(e) {
        CloseWindow("cancel");
    }
    // 关闭窗口
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) {
            return window.CloseOwnerWindow(action);
        } else {
            window.close(); 
        }           
    }
    
</script>
</body>
</html>